Conditions | 3 |
Paths | 4 |
Total Lines | 82 |
Code Lines | 43 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | // needed js files |
||
17 | init: function(editor) { |
||
18 | // if there is no user settings |
||
19 | // create an empty object |
||
20 | if (editor.config.pbckcode === undefined) { |
||
21 | editor.config.pbckcode = {}; |
||
22 | } |
||
23 | |||
24 | // default settings object |
||
25 | var DEFAULT_SETTINGS = { |
||
26 | cls: '', |
||
27 | modes: [ |
||
28 | ['HTML', 'html'], |
||
29 | ['CSS', 'css'], |
||
30 | ['PHP', 'php'], |
||
31 | ['JS', 'javascript'] |
||
32 | ], |
||
33 | theme: 'textmate', |
||
34 | tab_size: 4, |
||
35 | js: '//cdnjs.cloudflare.com/ajax/libs/ace/1.2.6/' |
||
36 | }; |
||
37 | |||
38 | // merge user settings with default settings |
||
39 | editor.settings = CKEDITOR.tools.extend(DEFAULT_SETTINGS, editor.config.pbckcode, true); |
||
40 | editor.settings.js = normalizeJsUrl(editor.settings.js); |
||
41 | |||
42 | // load CSS for the dialog |
||
43 | editor.on('instanceReady', function() { |
||
44 | CKEDITOR.document.appendStyleSheet(this.path + 'dialogs/style.css'); |
||
45 | }.bind(this)); |
||
46 | |||
47 | // add the button in the toolbar |
||
48 | editor.ui.addButton('pbckcode', { |
||
49 | label: editor.lang.pbckcode.addCode, |
||
50 | command: commandName, |
||
51 | toolbar: 'pbckcode' |
||
52 | }); |
||
53 | |||
54 | // link the button to the command |
||
55 | editor.addCommand(commandName, new CKEDITOR.dialogCommand('pbckcodeDialog', { |
||
56 | allowedContent: 'pre[*]{*}(*)' |
||
57 | }) |
||
58 | ); |
||
59 | |||
60 | // disable the button while the required js files are not loaded |
||
61 | editor.getCommand(commandName).disable(); |
||
62 | |||
63 | // add the plugin dialog element to the plugin |
||
64 | CKEDITOR.dialog.add('pbckcodeDialog', this.path + 'dialogs/pbckcode.js'); |
||
65 | |||
66 | // add the context menu |
||
67 | if (editor.contextMenu) { |
||
68 | editor.addMenuGroup('pbckcodeGroup'); |
||
69 | editor.addMenuItem('pbckcodeItem', { |
||
70 | label: editor.lang.pbckcode.editCode, |
||
71 | icon: this.path + 'icons/pbckcode.png', |
||
72 | command: commandName, |
||
73 | group: 'pbckcodeGroup' |
||
74 | }); |
||
75 | |||
76 | editor.contextMenu.addListener(function(element) { |
||
77 | if (element.getAscendant('pre', true)) { |
||
78 | return {pbckcodeItem: CKEDITOR.TRISTATE_OFF}; |
||
79 | } |
||
80 | }); |
||
81 | } |
||
82 | |||
83 | var scripts = [ |
||
84 | getScriptUrl(editor.settings.js, js.ace), |
||
85 | js.pbSyntaxHighlighter |
||
86 | ]; |
||
87 | |||
88 | // Load the required js files |
||
89 | // enable the button when loaded |
||
90 | CKEDITOR.scriptLoader.load(scripts, function() { |
||
91 | editor.getCommand(commandName).enable(); |
||
92 | |||
93 | // need ace to be loaded |
||
94 | CKEDITOR.scriptLoader.load([ |
||
95 | getScriptUrl(editor.settings.js, js.aceExtWhitespace) |
||
96 | ]); |
||
97 | }); |
||
98 | } |
||
99 | }); |
||
110 |
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.